library(quantmod)
## Warning: package 'quantmod' was built under R version 4.2.3
## Loading required package: xts
## Warning: package 'xts' was built under R version 4.2.3
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
## Loading required package: TTR
## Warning: package 'TTR' was built under R version 4.2.3
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library(dygraphs)
## Warning: package 'dygraphs' was built under R version 4.2.3
par(family="Palatino")
quantmod::getSymbols("GOOGL", src="yahoo")
## [1] "GOOGL"
m = tail(GOOGL, n=30)
m =m[,1:(ncol(m)-2)] # drops last two columns
names(m)<-c('Open', 'High', 'Low', 'Close') # renames columns for plotting
getwd()
## [1] "C:/Users/tayab/Desktop/Data Visualization/Assignment 9"
dygraph(m, main = "Google Stock Prices (Candlestick Chart)") |>
dyCandlestickGroup(c('Open', 'High', 'Low', 'Close')) |>
dyCandlestick() |>
dyLegend(show = "always", hideOnMouseOut = TRUE) |>
dyCSS("dygraph.css")
What i can see for Trend is that there is a slight increase through most of October but in late October we see a significant drop. Starting in november we start to see an increase in trend again. I don’t see any Stationarity presented. If it is part of a larger increase or decrease cycle then maybe.
# Dowloading a sample data
library(quantmod)
getSymbols("AAPL",
from = "2020/12/31",
to = "2022/12/31",
periodicity = "daily")
## [1] "AAPL"
# Finding the Class of AAPL
class(AAPL)
## [1] "xts" "zoo"
# TSStudio
library(TSstudio)
## Warning: package 'TSstudio' was built under R version 4.2.3
quantmod::getSymbols("AAPL", src="yahoo")
## [1] "AAPL"
class(AAPL)
## [1] "xts" "zoo"
ts_plot(AAPL$AAPL.Adjusted,
title = "Apple Stock prices",
Ytitle = "")
class(AAPL) # What class is this object? it is xts and zoo
## [1] "xts" "zoo"
# Some sample dataset from TSstudio
ts_seasonal(USgas, type = "") # month-year matrix data
## Warning in ts_seasonal(USgas, type = ""): The 'type' parameter is
## invalide,using the default option - 'normal'
#What class is USgas?
class(USgas)
## [1] "ts"
#Chart of USgas
ts_heatmap(USgas)
ts_cor(USgas) # ACF and PACF
The Trend we are seeing is that it appears to peak during the first half of the year and is at the least during June and May. From what we can conclude from the visuals is that there seem to be a seasonal trend. For Stationarity,It appears to return - surround the average. Below average during mid-year months, above average during January and adjacent months.
ts_lags(USgas, margin = .01)
# PDQ for USgas
library(forecast)
## Warning: package 'forecast' was built under R version 4.2.3
PDQbestfit <- auto.arima(USgas)
# This is the pdq:
summary(PDQbestfit)
## Series: USgas
## ARIMA(2,1,2)(2,1,1)[12]
##
## Coefficients:
## ar1 ar2 ma1 ma2 sar1 sar2 sma1
## 0.0091 0.1113 -0.4935 -0.3702 -0.0038 -0.2688 -0.7131
## s.e. 0.4090 0.1897 0.4018 0.3685 0.0865 0.0771 0.0729
##
## sigma^2 = 10631: log likelihood = -1366.25
## AIC=2748.5 AICc=2749.17 BIC=2775.83
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set 5.956789 98.67811 74.38266 0.1125963 3.53726 0.6398703 -0.01443522